import { Doc } from "@/api/interface/doc";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";

/**
 * 获取文档树
 * @param params 空间ID和管理员状态
 */
export const getDocTreeApi = (params: { FSpaceId: string; isAdmin?: boolean }) => {
  return http.get<Doc.DocNode[]>(PORT1 + `/doc/getDocTree`, params, { loading: false });
};

/**
 * 新增文档节点
 * @param params 文档节点参数
 */
export const addDocNodeApi = (params: Doc.AddDocNodeParams) => {
  return http.post<Doc.DocNode>(PORT1 + `/doc/addDocNode`, params);
};

/**
 * 更新文档节点
 * @param params 更新参数
 */
export const updateDocNodeApi = (params: Doc.UpdateDocNodeParams) => {
  return http.post<boolean>(PORT1 + `/doc/updateDocNode`, params);
};

/**
 * 删除文档节点
 * @param params 文档ID
 */
export const deleteDocNodeApi = (params: { FId: string }) => {
  return http.post<boolean>(PORT1 + `/doc/deleteDocNode`, params);
};

/**
 * 获取文档可见性设置
 * @param FDocId 文档ID
 */
export const getDocVisibilityApi = (params: { FDocId: string; isAdmin: boolean }) => {
  return http.get<Doc.VisibilitySettings>(PORT1 + `/doc/getVisibility`, params);
};

/**
 * 设置文档可见性
 * @param params 可见性设置参数
 */
export const setDocVisibilityApi = (params: Doc.SetVisibilityParams) => {
  return http.post<boolean>(PORT1 + `/doc/setVisibility`, params);
};

/**
 * 添加阅读记录
 */
export const addReadHistoryApi = (params: { FDocId: string }) => {
  return http.post<boolean>(PORT1 + `/doc/addReadHistory`, params, { loading: false });
};
